Skip to content

ROX-34138: Make HAProxy configurable#240

Open
mclasmeier wants to merge 16 commits into
mainfrom
mc/haproxy-configurable
Open

ROX-34138: Make HAProxy configurable#240
mclasmeier wants to merge 16 commits into
mainfrom
mc/haproxy-configurable

Conversation

@mclasmeier

@mclasmeier mclasmeier commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add HAProxyConfig to RoxieConfig with a configurable bind port (default 8080) and a disable toggle, replacing the previously hardcoded port and boolean HAProxyStarted flag.
  • Promote --config and --set to persistent root-level flags. This allows all subcommands (including roxie shell) to use them — e.g. roxie shell --set roxie.haProxy.bindPort=9090 — while deduplicating the config assembly logic into a shared assembleConfigForCommand helper.
  • Extract HAProxy config rendering into internal/haproxy package.
  • Propagate the roxieConfig structure when spawning sub-shells.

Manual tests

  • roxie deploy central spawns HAProxy on localhost:8080 by default.
  • roxie shell --set roxie.haProxy.bindPort=9090 can be used for re-attaching with HAProxy listening on localhost:9090.
  • HAProxy is not running anymore when the sub-shell terminates.
  • spawning of HAProxy can be disabled with --set roxie.haProxy.disabled=true.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@mclasmeier, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 38 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Enterprise

Run ID: 9bdd87ab-99a9-4071-8bbd-e86e3ff3a26a

📥 Commits

Reviewing files that changed from the base of the PR and between 2eff914 and d140a97.

📒 Files selected for processing (1)
  • cmd/main.go
📝 Walkthrough

Walkthrough

The change centralizes command configuration assembly, moves the config-file flag to the root command, adds configurable HAProxy bind ports, propagates Roxie settings through subshell execution, and records the active HAProxy port for Central connection output.

Changes

Configuration and HAProxy command flow

Layer / File(s) Summary
Centralized command configuration assembly
internal/deployer/config.go, cmd/config.go, cmd/main.go, cmd/flags.go, cmd/deploy.go, cmd/teardown.go, cmd/deploy_test.go
Configuration now combines defaults, optional user defaults, YAML file input, and command-line patches through shared merge behavior; the config flag is registered persistently and deploy flag tests use the root command path.
Configurable HAProxy subshell lifecycle
internal/types/central_deployment_info.go, internal/haproxy/*, cmd/subshell.go, cmd/deploy.go, cmd/shell.go
Roxie HAProxy settings propagate into subshell execution, rendered configuration uses the selected bind port, startup is conditional with deferred cleanup, and banners use the recorded HAProxy port.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Command
  participant runCommandOrSubshell
  participant tryStartHAProxy
  participant startHAProxy
  participant HAProxy
  Command->>runCommandOrSubshell: RoxieConfig
  runCommandOrSubshell->>tryStartHAProxy: CentralDeploymentInfo
  tryStartHAProxy->>startHAProxy: Validated startup request
  startHAProxy->>HAProxy: Start with rendered config and bind port
  HAProxy-->>runCommandOrSubshell: Active HAProxyPort
  runCommandOrSubshell-->>Command: Forwarded Central connection
Loading

Possibly related PRs

  • stackrox/roxie#201: Related subshell, HAProxy, banner, and Central deployment state changes.
  • stackrox/roxie#203: Related configuration assembly and YAML/user-default merging changes.

Suggested reviewers: alexvulaj, porridge

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.73% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: making HAProxy configurable.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch mc/haproxy-configurable

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mclasmeier mclasmeier force-pushed the mc/haproxy-configurable branch from 51d181c to 301552d Compare July 13, 2026 14:17

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
cmd/subshell.go (1)

150-153: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Consider capturing HAProxy stderr for diagnostics.

cmd.Stderr = nil discards all HAProxy error output. If HAProxy fails to bind or encounters config errors, there's no diagnostic information. Since cmd.Start() only verifies the process launched (not that it runs successfully), a silent startup failure would leave the user with a banner advertising a URL that doesn't work.

♻️ Proposed refactor: capture stderr for error reporting
 cmd := exec.Command("haproxy", "-f", configPath)
 cmd.Stdin = nil
 cmd.Stdout = nil
-cmd.Stderr = nil
+var stderr bytes.Buffer
+cmd.Stderr = &stderr
 
 if err := cmd.Start(); err != nil {
 	os.Remove(configPath)
 	return nil, "", fmt.Errorf("failed to start haproxy: %w", err)
 }
+// Give HAProxy a moment to fail on config/bind errors.
+time.Sleep(200 * time.Millisecond)
+if cmd.ProcessState != nil && cmd.ProcessState.Exited() {
+	os.Remove(configPath)
+	return nil, "", fmt.Errorf("haproxy exited immediately: %s", stderr.String())
+}
 
 centralDeploymentInfo.HAProxyPort = roxieConfig.HAProxy.BindPort
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/subshell.go` around lines 150 - 153, Update the HAProxy command setup
around exec.Command to capture stderr instead of discarding it, and use the
captured diagnostic output when cmd.Start or subsequent startup handling reports
failure. Preserve the existing stdin/stdout behavior while ensuring bind and
configuration errors are surfaced to the user rather than leaving a misleading
success banner.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cmd/subshell.go`:
- Around line 150-153: Update the HAProxy command setup around exec.Command to
capture stderr instead of discarding it, and use the captured diagnostic output
when cmd.Start or subsequent startup handling reports failure. Preserve the
existing stdin/stdout behavior while ensuring bind and configuration errors are
surfaced to the user rather than leaving a misleading success banner.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Enterprise

Run ID: 0abbd1c6-ac9a-4d12-bbff-21702a5b8f7c

📥 Commits

Reviewing files that changed from the base of the PR and between 51d181c and 301552d.

📒 Files selected for processing (9)
  • cmd/deploy.go
  • cmd/deploy_test.go
  • cmd/flags.go
  • cmd/main.go
  • cmd/shell.go
  • cmd/subshell.go
  • internal/deployer/config.go
  • internal/haproxy/config.go
  • internal/haproxy/config_test.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • cmd/shell.go
  • internal/deployer/config.go
  • cmd/deploy.go
  • cmd/main.go

@mclasmeier mclasmeier force-pushed the mc/haproxy-configurable branch from 301552d to 2eff914 Compare July 14, 2026 08:25
@mclasmeier

Copy link
Copy Markdown
Collaborator Author

@coderabbitai, fresh review please.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

@mclasmeier Sure, running a fresh full review of the PR now.

✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 55 minutes.

@mclasmeier mclasmeier changed the title Make HAProxy configurable ROX-34138: Make HAProxy configurable Jul 14, 2026
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
putComment timed out

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
cmd/main.go (1)

98-98: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Pass a pointer to mergo.Merge for consistency.

mergo.Merge expects the source argument to ideally be a pointer to avoid reflection overhead and potential type-matching issues. This also aligns with the usage in cmd/config.go and line 122 below.

♻️ Proposed fix
-			if err := mergo.Merge(config, configFromFile, mergo.WithOverride, mergo.WithoutDereference); err != nil {
+			if err := mergo.Merge(config, &configFromFile, mergo.WithOverride, mergo.WithoutDereference); err != nil {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/main.go` at line 98, Update the mergo.Merge call in the
configuration-loading flow to pass configFromFile as a pointer, matching the
pointer-based usage in cmd/config.go and the nearby merge call while preserving
the existing override and WithoutDereference options.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/main.go`:
- Around line 86-93: Update the filename handling in the withApplyFn callback so
"-" reads from os.Stdin using io.ReadAll, while other filenames continue through
os.ReadFile. Preserve the existing wrapped error handling and avoid replacing
the stdin path with the platform-specific "/dev/stdin" path.

---

Nitpick comments:
In `@cmd/main.go`:
- Line 98: Update the mergo.Merge call in the configuration-loading flow to pass
configFromFile as a pointer, matching the pointer-based usage in cmd/config.go
and the nearby merge call while preserving the existing override and
WithoutDereference options.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Enterprise

Run ID: 003c5b4e-2150-4f63-810f-537481ece039

📥 Commits

Reviewing files that changed from the base of the PR and between 301552d and 2eff914.

📒 Files selected for processing (13)
  • cmd/config.go
  • cmd/deploy.go
  • cmd/deploy_test.go
  • cmd/flags.go
  • cmd/main.go
  • cmd/shell.go
  • cmd/subshell.go
  • cmd/teardown.go
  • internal/deployer/config.go
  • internal/deployer/constants.go
  • internal/haproxy/config.go
  • internal/haproxy/config_test.go
  • internal/types/central_deployment_info.go
🚧 Files skipped from review as they are similar to previous changes (8)
  • internal/haproxy/config.go
  • cmd/shell.go
  • internal/haproxy/config_test.go
  • cmd/deploy_test.go
  • cmd/flags.go
  • internal/deployer/config.go
  • cmd/teardown.go
  • cmd/subshell.go

Comment thread cmd/main.go
@mclasmeier

Copy link
Copy Markdown
Collaborator Author

@coderabbitai, #240 (review) is addressed.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
gh api repos/stackrox/roxie/pulls/240/reviews --jq '.[] | select(.id==4692369489) | {id, body, state}'
gh api repos/stackrox/roxie/pulls/240/reviews/4692369489/comments --jq '.[] | {path, line, body}'

Length of output: 7714


🏁 Script executed:

#!/bin/bash
sed -n '75,130p' cmd/main.go

Length of output: 2495


Both flagged items are fixed: the io.ReadAll(os.Stdin) handling for - is now in place, and mergo.Merge at Line 103 passes &configFromFile as a pointer.

@mclasmeier Confirmed — thanks for the update!

@vladbologa vladbologa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, didn't know about the HAProxy support, in fact! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants